button = Object.extend(Object)

function button:new(TEXT,x,y,buttonX1,buttonY1,x1,y1)
    self.down  = 0;
    self.buttonWidth = x1
    self.buttonHeight = y1
    self.x = x;
    self.y = y --文本与边框间隔
    self.buttonX =buttonX1;
    self.buttonY =buttonY1;--按钮起始坐标
    self.text_X = self.buttonX + self.x;
    self.text_Y = self.buttonY + self.y;--文本起始坐标
    self.text = TEXT; --文本
   
end
function button.isMouseInButton(self)
return love.mouse.getX() >= self.buttonX
        and love.mouse.getX() < self.buttonX + self.buttonWidth
        and love.mouse.getY() >= self.buttonY
        and love.mouse.getY() < self.buttonY + self.buttonHeight
end

function button:draw_button(color1,color2,color3)
    self.color1=color1;
    self.color2 = color2;
    self.color3 = color3;
    myColor = {self.color1,self.color2,self.color3}
    if button.isMouseInButton(self) then
    love.graphics.setColor(0.1, .2, .5)
else
    love.graphics.setColor(myColor)
end
    love.graphics.rectangle("fill",self.buttonX,self.buttonY,self.buttonWidth,self.buttonHeight);
    love.graphics.setColor(1,1,1)
    local font1=love.graphics.newFont("方正喵呜体.ttf",20)
    love.graphics.setFont(font1)
    love.graphics.print(self.text,self.text_X,self.text_Y);
end

function button:isClick() 
    local moux= love.mouse.getX( )
    local mouy=love.mouse.getY( )
    if moux>=self.buttonX and moux <=self.buttonX+self.buttonWidth 
    and mouy>=self.buttonY and mouy<=self.buttonY+self.buttonHeight and love.mouse.isDown(1) then
     self.down =1;
    end
    if  self.down ==1 then
                return true
            else
                return false
            end
    end

function button:reset()
    self.down = 0
end
